/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  英雄数据
	/// module : structs
	/// </summary>
	public class HeroPOD : IPOD 
    {
        public readonly static Func<HeroPOD> FACTORY = () => new HeroPOD();
		public static Func<HeroPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  英雄唯一id
        /// </summary>
		public long id;
		/// <summary>
        ///  英雄cid(系统内唯一)
        /// </summary>
		public int cid;
		/// <summary>
        ///  觉醒等级
        /// </summary>
		public int awakenLevel;
		/// <summary>
        ///  等级
        /// </summary>
		public int level;
		/// <summary>
        ///  经验 -- 当前等级
        /// </summary>
		public int exp;
		/// <summary>
        ///  星级
        /// </summary>
		public int star;
		/// <summary>
        ///  皮肤cid -- 默认皮肤也穿上
        /// </summary>
		public int skinCid;
		/// <summary>
        ///  技能id到等级
        /// </summary>
        private Dictionary<int, int> m_skills;
		/// <summary>
        ///  属性 -- 全发
        /// </summary>
		public int[] attrs;
		/// <summary>
        ///  穿戴的装备，位置 -> 物品唯一id
        /// </summary>
        private Dictionary<int, long> m_equips;
		/// <summary>
        ///  装备等获得的技能
        /// </summary>
        private Dictionary<int, int> m_extraSkills;
		/// <summary>
        ///  装备的宠物
        /// </summary>
		public long petId;
		/// <summary>
        ///  命轨等级
        /// </summary>
		public int fateTrajectory;
		
		
        public Dictionary<int, int> skills
        {
            get
            {
                if(m_skills == null)
                {
                    m_skills = new();
                }
                return m_skills;
            }
            private set => m_skills = value;
        }
        public Dictionary<int, int> unsafe_skills
        {
        	get => m_skills;
        	set => m_skills = value;
        }
        public Dictionary<int, long> equips
        {
            get
            {
                if(m_equips == null)
                {
                    m_equips = new();
                }
                return m_equips;
            }
            private set => m_equips = value;
        }
        public Dictionary<int, long> unsafe_equips
        {
        	get => m_equips;
        	set => m_equips = value;
        }
        public Dictionary<int, int> extraSkills
        {
            get
            {
                if(m_extraSkills == null)
                {
                    m_extraSkills = new();
                }
                return m_extraSkills;
            }
            private set => m_extraSkills = value;
        }
        public Dictionary<int, int> unsafe_extraSkills
        {
        	get => m_extraSkills;
        	set => m_extraSkills = value;
        }
		
		/*-- constructors --*/
		public HeroPOD() {}
		public HeroPOD(long id, int cid, int awakenLevel, int level, int exp, int star, int skinCid, Dictionary<int, int> skills, int[] attrs, Dictionary<int, long> equips, Dictionary<int, int> extraSkills, long petId, int fateTrajectory) {
			this.id = id;
			this.cid = cid;
			this.awakenLevel = awakenLevel;
			this.level = level;
			this.exp = exp;
			this.star = star;
			this.skinCid = skinCid;
			this.m_skills = skills;
			this.attrs = attrs;
			this.m_equips = equips;
			this.m_extraSkills = extraSkills;
			this.petId = petId;
			this.fateTrajectory = fateTrajectory;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_int(awakenLevel);
            _out.Write_int(level);
            _out.Write_int(exp);
            _out.Write_int(star);
            _out.Write_int(skinCid);
            _out.Write_map_int_int(m_skills);
            _out.Write_intArr(attrs);
            _out.Write_map_int_long(m_equips);
            _out.Write_map_int_int(m_extraSkills);
            _out.Write_long(petId);
            _out.Write_int(fateTrajectory);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            awakenLevel = _in.Read_int();
            if(!_in.HasRemaining()) return;
            level = _in.Read_int();
            if(!_in.HasRemaining()) return;
            exp = _in.Read_int();
            if(!_in.HasRemaining()) return;
            star = _in.Read_int();
            if(!_in.HasRemaining()) return;
            skinCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_skills = _in.Read_map_int_int();
            if(!_in.HasRemaining()) return;
            attrs = _in.Read_intArr();
            if(!_in.HasRemaining()) return;
            m_equips = _in.Read_map_int_long();
            if(!_in.HasRemaining()) return;
            m_extraSkills = _in.Read_map_int_int();
            if(!_in.HasRemaining()) return;
            petId = _in.Read_long();
            if(!_in.HasRemaining()) return;
            fateTrajectory = _in.Read_int();
        }
		
		public HeroPOD Clone() {
            HeroPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.awakenLevel = awakenLevel;
            o.level = level;
            o.exp = exp;
            o.star = star;
            o.skinCid = skinCid;
            if (m_skills != null) {
                o.m_skills = new (m_skills);
            }
            if (attrs != null) {
                o.attrs = (int[])attrs.Clone();
            }
            if (m_equips != null) {
                o.m_equips = new (m_equips);
            }
            if (m_extraSkills != null) {
                o.m_extraSkills = new (m_extraSkills);
            }
            o.petId = petId;
            o.fateTrajectory = fateTrajectory;
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            awakenLevel = default;
            level = default;
            exp = default;
            star = default;
            skinCid = default;
            m_skills = default;
            attrs = default;
            m_equips = default;
            m_extraSkills = default;
            petId = default;
            fateTrajectory = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "HeroPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", awakenLevel=";
			str += awakenLevel;
			str += ", level=";
			str += level;
			str += ", exp=";
			str += exp;
			str += ", star=";
			str += star;
			str += ", skinCid=";
			str += skinCid;
			str += ", skills=";
			str += m_skills.ToString<int, int>();
			str += ", attrs=";
			str += attrs;
			str += ", equips=";
			str += m_equips.ToString<int, long>();
			str += ", extraSkills=";
			str += m_extraSkills.ToString<int, int>();
			str += ", petId=";
			str += petId;
			str += ", fateTrajectory=";
			str += fateTrajectory;
			str += "]";
			return str;
		}
		
	}
}